package com.jinzhi.jzweb.controller.api;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jinzhi.common.service.DictService;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.JazInformDO;
import com.jinzhi.jzweb.domain.JazSysBannerDO;
import com.jinzhi.jzweb.domain.JazSysProjectDO;
import com.jinzhi.jzweb.service.JazInformService;
import com.jinzhi.jzweb.service.JazSysBannerService;
import com.jinzhi.jzweb.service.JazSysProjectService;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 首页相关接口
 * @author mengzhichao
 * @create 2023-04-18-14:03
 */

@RestController
@RequestMapping("/jzApi/index")
public class ApiIndexController {


    @Autowired
    private JazSysProjectService jazSysProjectService;  //服务表

    @Autowired
    private JazSysBannerService jazSysBannerService; //Banner表

    @Autowired
    private JazInformService jazInformService; //新闻滚动表



    /**
     * 首页主要服务查询
     * 首页主要服务查询  8个
     * @return
     */
    @GetMapping("/list")
    public Result<List<JazSysProjectDO>> list(){
        Wrapper<JazSysProjectDO> wrapper = new EntityWrapper<>();
        wrapper.eq("status",0); //正常状态
        wrapper.orderBy("sort");
        List<JazSysProjectDO> jazSysProjectDOS = jazSysProjectService.selectList(wrapper);
//        jazSysProjectDOS =  jazSysProjectDOS.stream().limit(8).collect(Collectors.toList());  //只要前8个项目
        return Result.ok(jazSysProjectDOS);
    }



    /**
     * 首页热门服务查询  3个
     * @return
     */
    @GetMapping("/listTop3")
    public Result<List<JazSysProjectDO>> listTop3(){
        Wrapper<JazSysProjectDO> wrapper = new EntityWrapper<>();
        wrapper.eq("status",0); //正常状态
        wrapper.orderBy("sort");
        List<JazSysProjectDO> jazSysProjectDOS = jazSysProjectService.selectList(wrapper);
        jazSysProjectDOS =  jazSysProjectDOS.stream().limit(3).collect(Collectors.toList());  //只要前3个项目
        return Result.ok(jazSysProjectDOS);
    }




    /**
     * 首页banner图
     *
     * index = 1首页   =2 个人中心
     * @return
     */
    @GetMapping("/banner")
    public Result<List<JazSysBannerDO>> banner(String index){
        Wrapper<JazSysBannerDO> wrapper = new EntityWrapper<>();
        wrapper.eq("status",0); //正常状态
        wrapper.eq("position",index);
        wrapper.orderBy("sort");
        List<JazSysBannerDO> jazSysBannerDOS = jazSysBannerService.selectList(wrapper);
        return Result.ok(jazSysBannerDOS);
    }



    /**
     * 首页滚动新闻查询
     * @return
     */
    @GetMapping("/inform")
    public Result<List<String>> inform(){
        List<String> collect = jazInformService.selectList(null).stream().map(JazInformDO::getContent).collect(Collectors.toList());
        return Result.ok(collect);
    }




}
